%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% MIT License
%
% Copyright (c) 2016 Microsoft
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
% function nIndex=getPDSCHModulation(nModulation, nTBSindex, nRedundancyVersion)
%
% Get MCS index for given values of modulation, TBS index and redundancy version
% from Table 7.1.7.1-1 in 36.213 (page 40)
%
function nIndex=mcs_table(nModulation, nTBSindex)

aTable = [0 2 0; ...
          1 2 1; ...
          2 2 2; ...
          3 2 3; ...
          4 2 4; ...
          5 2 5; ...
          6 2 6; ...
          7 2 7; ...
          8 2 8; ...
          9 2 9; ...
          10 4 9; ...
          11 4 10; ...
          12 4 11; ...
          13 4 12; ...
          14 4 13; ...
          15 4 14; ...
          16 4 15; ...
          17 6 15; ...
          18 6 16; ...
          19 6 17; ...
          20 6 18; ...
          21 6 19; ...
          22 6 20; ...
          23 6 21; ...
          24 6 22; ...
          25 6 23; ...
          26 6 24; ...
          27 6 25; ...
          28 6 26; ...
          29 2 -1; ...
          30 4 -1; ...
          31 6 -1];

index = find(aTable(:,2) == nModulation & aTable(:,3) == nTBSindex);

if isempty(index)
  nIndex = -1;
else
  nIndex = aTable(index, 1);
end
